// 关于 category 商品分类的二级仓库
import { defineStore } from "pinia";
import { reqC1, reqC2, reqC3 } from "@/api/product/attr";
import type {
  CategoryResponseData,
  CategoryState,
} from "@/api/product/attr/type";
const useCategoryStore = defineStore("Category", {
  state: (): CategoryState => {
    return {
      c1Arr: [], // 一级分类列表
      c2Arr: [], // 二级分类列表
      c3Arr: [], // 三级分类列表
      c1Id: "", // 一级分类id
      c2Id: "", // 二级分类id
      c3Id: "", // 三级分类id
    };
  },
  actions: {
    async getC1() {
      const result: CategoryResponseData = await reqC1();
      this.c1Arr = result.data;
    },
    async getC2(id: number | string) {
      const result: CategoryResponseData = await reqC2(id);
      this.c2Arr = result.data;
    },
    async getC3(id: number | string) {
      const result: CategoryResponseData = await reqC3(id);
      this.c3Arr = result.data;
    },
  },
  getters: {},
});

export default useCategoryStore;
